package java8.lamb;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * Created by fangjicai on 2020/6/6.
 */
public class SelfIntefaceTest {
    public static void main(String[] args) {
        Predicate<String> predicate=(s)->s.length()>0;
        predicate.test("foo");//true
        //取反
        predicate.negate().test("foo");//false
        Predicate<Boolean> nonNull = Objects::nonNull;
        Predicate<Boolean> isNull = Objects::isNull;
        Predicate<String> isEmpty=String::isEmpty;
        Predicate<String> isNotEmpty=isEmpty.negate();

        Function<String,Integer> toInteger=Integer::valueOf;
        Function<String,String> backToString =toInteger.andThen(String::valueOf);
        String result = backToString.apply("123");
        System.out.println(result);

        Supplier<Person> personSupplier = Person::new;
        personSupplier.get();   // new Person

        Consumer<Person> greeter = (p) -> System.out.println("Hello, " + p.firstName);
        greeter.accept(new Person("Luke", "Skywalker"));

        Optional<String> optional = Optional.of("bam");

        optional.isPresent();           // true
        optional.get();                 // "bam"
        optional.orElse("fallback");    // "bam"

        optional.ifPresent((s) -> System.out.println(s.charAt(0)));     // "b"




    }
}
